import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index.js'
import Index from '../views/Index.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Index,
    children: [{
        path: '',
        redirect: '/home'
      },
      {
        path: '/home',
        name: 'Home',
        component: () => import("../views/Home.vue")
      },
      {
        path: '/class',
        name: 'Class',
        component: () => import("../views/Class.vue")
      },
      {
        path: '/market',
        name: 'Market',
        component: () => import("../views/Market.vue")
      },
      {
        path: '/shoppingcar',
        name: 'ShoppingCar',
        component: () => import("../views/ShoppingCar.vue")
      },
      {
        path: '/mine',
        name: 'Mine',
        component: () => import("../views/Mine.vue")
      }
    ]
  },
  {
    path:'/login',
    name:'Login',
    component: () => import("../views/Login.vue")
  },
{
  path:'/menusearch',
  name:'MenuSearch',
  component: () => import("../views/MenuSearch.vue")
},
{
  path:'/homedishes',
  name:'HomeDishes',
  component: () => import("../views/HomeDishes.vue"),

},
{
  path:'/foodcontent',
  name:'FoodContent',
  component: () => import("../views/FoodContent.vue"),
},
{
  path:'/goodcontrent',
  name:'GoodContent',
  component: () => import("../views/GoodContent.vue")
},
{
  path: '/vegetablebasket',
  name: 'VegetableBasket',
  component: () => import('../views/VegetableBasket.vue')
},
{
  path: '/myattention',
  name: 'MyAttention',
  component: () => import('../views/MyAttention.vue')
},
{
  path: '/mywork',
  name: 'MyWork',
  component: () => import('../views/MyWork.vue')
},
{
  path: '/mycollection',
  name: 'MyCollection',
  component: () => import('../views/MyCollection.vue')
},
{
  path: '/userdetails',
  name: 'UserDetails',
  component: () => import('../views/UserDetails.vue')
},
{
  path: '/myshoppingaddress',
  name: 'MyshoppingAddress',
  component: () => import('../views/MyshoppingAddress.vue')
},
{
  path: 'addaddress',
  name: 'AddAddress',
  component: () => import('../views/AddAddress.vue')
},
{
  path: 'addressselect',
  name: 'AddressSelect',
  component: () => import('../views/AddressSelect.vue')
},{
  path: 'addressedit',
  name: 'AddressEdit',
  component: () => import('../views/AddressEdit.vue')
},
{
  path:'/buy',
  name:'Buy',
  component: () => import("../views/Buy.vue")
},
{
  path:'/myorder',
  name:'MyOrder',
  component: () => import("../views/MyOrder.vue")
},
{
  path:'/allorder',
  name:'AllOrder',
  component: () => import("../views/AllOrder.vue")
},
{
  path:'/share',
  name:'Share',
  component: () => import("../views/Share.vue")
},
{
  path:'/bianji',
  name:'BianJi',
  component: () => import("../views/BianJi.vue")
},
{
  path:'/set',
  name:'Set',
  component: () => import("../views/Set.vue")
},
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if (to.name === 'Login' || to.name === 'Home' || to.name === 'Mine' || localStorage.name != null) {
    next()
  } else {
    next({
      name: 'Login'
    })
  }
})

export default router
